package com.macro.mall.controller;

import java.util.List;

import com.macro.mall.dto.BmsMuseumParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsMuseumDetail;
import com.macro.mall.model.BmsMuseum;
import com.macro.mall.query.BmsMuseumQuery;
import com.macro.mall.service.BmsMuseumService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;

@Controller
@Api(tags = "BmsMuseumController")
@Tag(name = "BmsMuseumController", description = "文博项目")
@RequestMapping("/museumProject")
public class BmsMuseumController {

    @Autowired
    private BmsMuseumService bmsMuseumService;

    @ApiOperation("分页查询文博项目")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsMuseum>> getList(@RequestBody BmsMuseumQuery query) {
        List<BmsMuseum> bmsMuseumProjectList = bmsMuseumService.getList(query);
        return CommonResult.success(CommonPage.restPage(bmsMuseumProjectList));
    }

    @ApiOperation("查询文博项目列表所有数据")
    @RequestMapping(value = "/findAllList", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> findAllList() {
        return CommonResult.success(bmsMuseumService.findAllList());
    }

    @ApiOperation("添加文博项目")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsMuseumParam bmsMuseumParam) {
        int count = bmsMuseumService.create(bmsMuseumParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }


    @ApiOperation("修改文博项目")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsMuseumParam bmsMuseumParam) {
        int count = bmsMuseumService.update(bmsMuseumParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("根据id获取文博项目信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsMuseumDetail> getItem(@PathVariable Long id) {
        BmsMuseumDetail bmsFeedBackDetail = bmsMuseumService.getItem(id);
        return CommonResult.success(bmsFeedBackDetail);
    }

    @ApiOperation("删除文博项目")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> delete(@RequestParam("ids") List<Long> ids) {
        int count = bmsMuseumService.delete(ids);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

}
